package com.csxy.lxl.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csxy.lxl.R;
import com.csxy.lxl.entity.EduCourse;
import com.csxy.lxl.entity.EduTeacher;
import com.csxy.lxl.service.EduCourseService;
import com.csxy.lxl.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherFront")
public class TeacherFrontController {
    @Autowired
    private EduTeacherService eduTeacherService;
    @Autowired
    private EduCourseService eduCourseService;

    @GetMapping("/getTeacherFrontPageList/{page}/{limit}")
    public R getTeacherFrontPageList(@PathVariable long page, @PathVariable long limit) {
        Page<EduTeacher> pageTeacher = new Page<>(page, limit);
        Map<String, Object> map = eduTeacherService.getTeacherFrontList(pageTeacher);
        //返回分页中的所有数据
        return R.ok().data(map);
    }

    @GetMapping("/getTeacherInfo/{id}")
    public R getTeacherFrontInfo(@PathVariable String id) {
        //根据讲师id查询讲师基本信息
        EduTeacher eduTeacher = eduTeacherService.getById(id);
        //查询教师所讲课程信息
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", id);
        //根据讲师id查询讲师课程
        List<EduCourse> courseList = eduCourseService.list(wrapper);
        return R.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }
}
